#pragma once

#include "cocos2d.h"
#include "chipmunk.h"
#include "PhiysicsSprite.h"

USING_NS_CC;
using namespace std;
using namespace cocos2d;

class CPhysicsLayer : public CCLayer
{
public:
	CPhysicsLayer();
	~CPhysicsLayer();
	void onEnter();
	void initPhysics();
	void reset(CCObject* sender);
	CCSpriteBatchNode* InitSprite(const char* File);

	void addNewSpriteAtPosition(CCSprite* pSprite,CCPoint p);
	void addBatchNodeAtPosition(CCSpriteBatchNode* pNode, CCPoint p);
	void update(float dt);
	virtual void ccTouchesBegan(CCSet* touches, CCEvent* event);
	virtual void ccTouchesMoved(CCSet* touches, CCEvent* event);
	virtual void ccTouchesEnded(CCSet* touches, CCEvent* event);
	virtual void didAccelerate(CCAcceleration* pAccelerationValue);
	void MoveBatchNodeToLeft(CCSpriteBatchNode* pNode);
	void MoveBatchNodeToRight(CCSpriteBatchNode* pNode);

	void AddNewPhysicsObject(CCSprite* pSprite);

private:
	CCTexture2D* m_pSpriteTexture; // weak ref
	cpSpace* m_pSpace; // strong ref
	cpShape* m_pWalls[4];
	cpConstraint * m_pMouseJoint;

	cpBody* m_pMouseBody;
	cpBody* m_pBallBody;
};
